package cn.net.shuxing.yifu.common.back.controller;

import cn.net.shuxing.yifu.common.bean.*;
import cn.net.shuxing.yifu.common.constant.*;
import cn.net.shuxing.yifu.common.dto.BaseDto;
import cn.net.shuxing.yifu.common.dto.CashDealRecordDto;
import cn.net.shuxing.yifu.common.dto.TransferHistoryDto;
import cn.net.shuxing.yifu.common.service.*;
import cn.net.shuxing.yifu.common.util.DateUtil;
import cn.net.shuxing.yifu.common.util.JedisUtil;
import cn.net.shuxing.yifu.common.util.RedisKeyCreator;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/back/finance")
public class FinanceController {
    @Autowired
    private UserCashHistoryService userCashHistoryService;

    @Autowired
    private ShareholderBonusService shareholderBonusService;

    @Autowired
    private OpenPriceHistoryService openPriceHistoryService;

    @Autowired
    private FeePayHistoryService feePayHistoryService;

    @Autowired
    private UserDealHistoryService userDealHistoryService;

    @Autowired
    private ShareholderBonusListService shareholderBonusListService;

    @Autowired
    private AliveCoinActivateHistoryService aliveCoinActivateHistoryService;

    @Autowired
    private ShareholderCommonService shareholderCommonService;

    @Autowired
    private CashWalletService cashWalletService;

    @Autowired
    private UserWithdrawalCashService userWithdrawalCashService;

    @Autowired
    private UserCommonService userCommonService;

    @Autowired
    private JedisUtil jedisUtil;

    //列表展示财务统计
    @RequestMapping("/statistical/list")
    public BaseDto getStatisticalList() {
        BaseDto baseDto = new BaseDto();

        StatisticalList list = new StatisticalList();

        //分红总额 totalDividends
        BigDecimal totalDivdends = shareholderCommonService.getTotalDivdends();
        list.setTotalDividends(totalDivdends);
        //本月分红 monthDividends
        BigDecimal monthDivdends = shareholderCommonService.getMonthDivdends();
        list.setMonthDivdends(monthDivdends);
        //股东可提现金额 s_withdrawalCash
        BigDecimal s_withdrawalCash = cashWalletService.getTotalWithdrawalCash(UserType.SHAREHOLDER);
        list.setS_withdrawalCash(s_withdrawalCash);
        //股东累计提现金额 s_withdrawalCashCount
        BigDecimal s_withdrawalCashCount = userWithdrawalCashService.getWithdrawalCashCountByUserType(UserType.SHAREHOLDER);
        list.setS_withdrawalCashCount(s_withdrawalCashCount);
        //股东转账总额 s_totalTransfer
        BigDecimal s_totalTransfer = userCommonService.getTotalTransferByUserType(UserType.SHAREHOLDER);
        list.setS_totalTransfer(s_totalTransfer);
        //股东本月转账 s_monthTransfer
        BigDecimal s_monthTransfer = userCommonService.getMonthTransferByUserType(UserType.SHAREHOLDER);
        list.setS_monthTransfer(s_monthTransfer);
        //配发总额 s_totalDistribute
        BigDecimal totalDistribute = shareholderCommonService.getTotalDistribute();
        list.setS_totalDistribute(totalDistribute);
        //本月配发 s_monthDistribute
        BigDecimal monthDistribute = shareholderCommonService.getMonthDistribute();
        list.setS_monthDistribute(monthDistribute);
        //会员买入总额 m_totalBuy
        BigDecimal total = userDealHistoryService.getHangBuyTotal();
        list.setM_totalBuy(total);
        //会员本月买入 m_monthBuy
        BigDecimal month = userDealHistoryService.getHangBuyMonth();
        list.setM_monthBuy(month);
        //会员卖出总额 m_totalSale
        list.setM_totalSale(userDealHistoryService.getHangSaleTotal());
        //会员本月卖出 m_monthSale
        list.setM_monthSale(userDealHistoryService.getHangSaleMonth());
        //会员可提现金额 m_withdrawalCash
        list.setM_withdrawalCash(cashWalletService.getTotalWithdrawalCash(UserType.MEMBER));
        //会员累计提现金额 m_withdrawalCashCount
        list.setM_withdrawalCashCount(userWithdrawalCashService.getWithdrawalCashCountByUserType(UserType.MEMBER));
        //会员转账总数 m_totalTransfer
        list.setM_totalTransfer(userCommonService.getTotalTransferByUserType(UserType.MEMBER));
        //会员本月转账 m_monthTransfer
        list.setM_monthTransfer(userCommonService.getMonthTransferByUserType(UserType.MEMBER));
        //手续费总额 totalFee
        list.setTotalFee(feePayHistoryService.getTotal());
        //本月手续费 monthFee
        list.setMonthFee(feePayHistoryService.getMonth());
//            guoqishijian
        baseDto.setData(list);

        //订单总数 totalOrderNum
        //本月订单数 monthOrderNum
        //订单总金额 totalOrderPrice
        //本月订单金额 monthOrderPrice
        return baseDto;
    }

    //股东分红记录
    @RequestMapping("/statistical/dividenshistory")
    public BaseDto getDividensHistory(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                                      @RequestParam(defaultValue = "15", value = "pageSize") int pageSize) {
        BaseDto baseDto = new BaseDto();
        //Page page = PageHelper.startPage(pageNum,pageSize);
        List<ShareholderBonusList> all = shareholderBonusListService.getAll();
        PageInfo<ShareholderBonusList> pageInfo = new PageInfo<>(all);
        //pageInfo.setTotal(page.getTotal());
        baseDto.setData(pageInfo);
        return baseDto;
    }

    //股东提现记录
    @RequestMapping("/statistical/s_withdrawalcashhistory")
    public BaseDto getWithdrawalCashHistory(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                                            @RequestParam(defaultValue = "15", value = "pageSize") int pageSize) {
        BaseDto baseDto = new BaseDto();
        //Page page = PageHelper.startPage(pageNum,pageSize);
        PageInfo<UserWithdrawalCash> pageInfo = new PageInfo<>(userWithdrawalCashService.getsByUserType(UserType.SHAREHOLDER));
        //pageInfo.setTotal(page.getTotal());
        baseDto.setData(pageInfo);
        return baseDto;
    }

    //股东转账记录
    @RequestMapping("/statistical/s_transferhistory")
    public BaseDto getTransferHistory(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                                      @RequestParam(defaultValue = "15", value = "pageSize") int pageSize) {
        BaseDto baseDto = new BaseDto();
        //Page page = PageHelper.startPage(pageNum,pageSize);
        PageInfo<UserTransfer> pageInfo = new PageInfo<>(userCommonService.getTransferHistoryByUserType(UserType.SHAREHOLDER));
        //pageInfo.setTotal(page.getTotal());
        baseDto.setData(pageInfo);
        return baseDto;
    }

    //配发历史记录
    @RequestMapping("/statistical/distributehistory")
    public BaseDto getDistributeHistory(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                                        @RequestParam(defaultValue = "15", value = "pageSize") int pageSize,
                                        Integer userId) {
        BaseDto baseDto = new BaseDto();
        //Page page = PageHelper.startPage(pageNum,pageSize);
        PageInfo<AliveCoinActivateHistory> pageInfo = new PageInfo<>(aliveCoinActivateHistoryService.getByShareholderId(userId));
        //pageInfo.setTotal(page.getTotal());
        baseDto.setData(pageInfo);
        return baseDto;
    }

    //会员买入交易记录
    @RequestMapping("/statistical/hangbuyhistory")
    public BaseDto getHangBuyHistory(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                                     @RequestParam(defaultValue = "15", value = "pageSize") int pageSize) {
        BaseDto baseDto = new BaseDto();
        //Page page = PageHelper.startPage(pageNum,pageSize);
        PageInfo<UserDealHistory> pageInfo = new PageInfo<>(userDealHistoryService.getDealHistoryByDealScene(DealScene.HANG_BUY));
        //pageInfo.setTotal(page.getTotal());
        baseDto.setData(pageInfo);
        return baseDto;
    }

    //会员卖出交易记录
    @RequestMapping("/statistical/hangsalehistory")
    public BaseDto getHangSaleHistory(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                                      @RequestParam(defaultValue = "15", value = "pageSize") int pageSize) {
        BaseDto baseDto = new BaseDto();
        //Page page = PageHelper.startPage(pageNum,pageSize);
        PageInfo<UserDealHistory> pageInfo = new PageInfo<>(userDealHistoryService.getDealHistoryByDealScene(DealScene.HANG_SALE));
        //pageInfo.setTotal(page.getTotal());
        baseDto.setData(pageInfo);
        return baseDto;
    }

    @RequestMapping("/statistical/userDealHistory")
    public BaseDto getDealHistory(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                                  @RequestParam(defaultValue = "15", value = "pageSize") int pageSize,
                                  Integer userId) {
        //Page page = PageHelper.startPage(pageNum,pageSize);
        List<UserDealHistory> dealHistoryByHangBuyAndHangSale = userDealHistoryService.getsDealHistoryByUserId(userId);
        BaseDto baseDto = new BaseDto();
        PageInfo<UserDealHistory> pageInfo = new PageInfo<>(dealHistoryByHangBuyAndHangSale);
        //pageInfo.setTotal(page.getTotal());
        baseDto.setData(pageInfo);
        return baseDto;
    }

    //会员提现记录
    @RequestMapping("/statistical/m_withdrawalcashhistory")
    public BaseDto getMWithdrawalCashHistory(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                                             @RequestParam(defaultValue = "15", value = "pageSize") int pageSize) {
        BaseDto baseDto = new BaseDto();
        //Page page = PageHelper.startPage(pageNum,pageSize);
        PageInfo<UserWithdrawalCash> pageInfo = new PageInfo<>(userWithdrawalCashService.getsByUserType(UserType.MEMBER));
        //pageInfo.setTotal(page.getTotal());
        baseDto.setData(pageInfo);
        return baseDto;
    }

    //会员转账记录
    @RequestMapping("/statistical/m_transferhistory")
    public BaseDto getMTransferHistory(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                                       @RequestParam(defaultValue = "15", value = "pageSize") int pageSize) {
        BaseDto baseDto = new BaseDto();
        //Page page = PageHelper.startPage(pageNum,pageSize);
        PageInfo<UserTransfer> pageInfo = new PageInfo<>(userCommonService.getTransferHistoryByUserType(UserType.MEMBER));
        //pageInfo.setTotal(page.getTotal());
        baseDto.setData(pageInfo);
        return baseDto;
    }

    /**
     * 某userId转账记录
     *
     * @param userId
     */
    @RequestMapping("statistical/transferHistory")
    public BaseDto getTransferHistoryByUserId(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                                              @RequestParam(defaultValue = "15", value = "pageSize") int pageSize,
                                              Integer userId,
                                              Integer userType) {
        List<TransferHistoryDto> userTransferToShareholder = userDealHistoryService.getUserTransferHistory(userId, pageNum, pageSize,userType);
        return BaseDto.ok(userTransferToShareholder);
    }

    /**
     * 某userId转股东活币数量
     *
     * @param userId
     */
    @RequestMapping("statistical/sToSTransfer")
    public BaseDto sToSTransfer(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                                @RequestParam(defaultValue = "15", value = "pageSize") int pageSize,
                                Integer userId) {
        List<TransferHistoryDto> userTransferToShareholder = userDealHistoryService.getUserTransferToShareholder(userId, pageNum, pageSize);
        return BaseDto.ok(userTransferToShareholder);
    }


    //手续费记录
    @RequestMapping("/statistical/feehistory")
    public BaseDto getFeeHistory(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                                 @RequestParam(defaultValue = "15", value = "pageSize") int pageSize) {
        BaseDto baseDto = new BaseDto();
        //Page page = PageHelper.startPage(pageNum,pageSize);
        PageInfo<FeePayHistory> pageInfo = new PageInfo<>(feePayHistoryService.getAll());
        //pageInfo.setTotal(page.getTotal());
        baseDto.setData(pageInfo);
        return baseDto;
    }

    /**
     * 给所有人发放分红
     *
     * @param count
     * @param coinTypeId
     * @return
     */
    @RequestMapping("/dividends/add")
    public void dividendsAdd(HttpServletResponse response, BigDecimal count, Integer coinTypeId) throws IOException {
        BaseDto baseDto = shareholderCommonService.giveShareholderBonus(count, coinTypeId);
        response.sendRedirect("addpage");
    }

    /**
     * 分红统计
     *
     * @return
     */
    @RequestMapping("/dividends/list")
    public BaseDto dividendsList(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                                 @RequestParam(defaultValue = "15", value = "pageSize") int pageSize) {
        BaseDto baseDto = new BaseDto();
        //Page page = PageHelper.startPage(pageNum,pageSize);
        PageInfo<ShareholderBonusList> pageInfo = new PageInfo<>(shareholderBonusListService.getAll());
        //pageInfo.setTotal(page.getTotal());
        baseDto.setData(pageInfo);
        return baseDto;
    }

    /**
     * 所有成功分红的记录
     *
     * @return
     */
    @RequestMapping("/dividends/userList")
    public BaseDto dividendsUserList(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                                     @RequestParam(defaultValue = "15", value = "pageSize") int pageSize) {
        //Page page = PageHelper.startPage(pageNum,pageSize);
        List<ShareholderBonus> dividensHistory = shareholderCommonService.getDividensHistory();
        BaseDto baseDto = new BaseDto();
        PageInfo<ShareholderBonus> pageInfo = new PageInfo<>(dividensHistory);
        //pageInfo.setTotal(page.getTotal());
        baseDto.setData(pageInfo);
        return baseDto;
    }

    /**
     * 单个股东分红记录
     *
     * @return
     */
    @RequestMapping("/dividends/user")
    public BaseDto dividendsUser(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                                 @RequestParam(defaultValue = "15", value = "pageSize") int pageSize,
                                 Integer userId) {
        //Page page = PageHelper.startPage(pageNum,pageSize);
        List<ShareholderBonus> shareholderBonuses = shareholderBonusService.getsByShareholderId(userId);
        BaseDto baseDto = new BaseDto();
        PageInfo<ShareholderBonus> pageInfo = new PageInfo<>(shareholderBonuses);
        //pageInfo.setTotal(page.getTotal());
        baseDto.setData(pageInfo);
        return baseDto;
    }

    /**
     * 单个股东分红记录
     *
     * @return
     */
    @RequestMapping("/dividends/userMonth")
    public BaseDto dividendsUserMonth(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                                      @RequestParam(defaultValue = "15", value = "pageSize") int pageSize,
                                      Integer userId) {
        //Page page = PageHelper.startPage(pageNum,pageSize);
        List<ShareholderBonus> shareholderBonuses = shareholderBonusService.getThisMonthBonusByShareholderId(userId);
        BaseDto baseDto = new BaseDto();
        baseDto.setData(new PageInfo<ShareholderBonus>(shareholderBonuses));
        return baseDto;
    }

    /**
     * 搜索股东分红记录
     *
     * @param phoneNum
     * @param idCardNum
     */
    @RequestMapping("/dividends/search")
    public BaseDto searchPhoneNumAndIdCard(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                                           @RequestParam(defaultValue = "15", value = "pageSize") int pageSize,
                                           String phoneNum, String idCardNum) {
        List<ShareholderBonus> shareholderBonusList = shareholderCommonService.getDisDividendsListByPhoneNumAndIdCard(phoneNum, idCardNum);
        BaseDto baseDto = new BaseDto();
        //Page page = PageHelper.startPage(pageNum,pageSize);
        PageInfo<ShareholderBonus> pageInfo = new PageInfo<>(shareholderBonusList);
        //pageInfo.setTotal(page.getTotal());
        baseDto.setData(pageInfo);
        return baseDto;
    }

    /**
     * 给用户补发分红并返回列表
     *
     * @param bonusId 分红历史id
     * @param userId  用户id
     * @throws IOException
     */
    @RequestMapping("/dividends/update")
    public void updateShareholderDividends(
            HttpServletResponse response,
            Integer bonusId, Integer userId) throws IOException {
        Map map = shareholderCommonService.updateDividends(bonusId, userId);
        response.sendRedirect("searchpage?phoneNum=" + map.get("phoneNum") + "&idCardNum=" + map.get("idCardNum") + "");
    }

    @RequestMapping("/statistical/withdrawList")
    public BaseDto withdrawalList(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                                  @RequestParam(defaultValue = "15", value = "pageSize") int pageSize) {
        //Page page = PageHelper.startPage(pageNum,pageSize);
        List<UserWithdrawalCash> all = userWithdrawalCashService.getAll();
        BaseDto baseDto = new BaseDto();
        PageInfo<UserWithdrawalCash> pageInfo = new PageInfo<>(userWithdrawalCashService.getAll());
        //pageInfo.setTotal(page.getTotal());
        baseDto.setData(pageInfo);
        return baseDto;
    }

    @RequestMapping("/statistical/pass")
    public void withdrawalPass(HttpServletResponse response,
                               Integer id) throws IOException {
        UserWithdrawalCash userWithdrawalCash = userWithdrawalCashService.getByPrimaryKey(id);
        userWithdrawalCash.setState(UserWithdrawalState.TRANSFERING);
        userWithdrawalCashService.update(userWithdrawalCash);
        response.sendRedirect("withdrawCashPage");
    }

    @RequestMapping("/statistical/refuse")
    public void withdrawalRefuse(HttpServletResponse response,
                                 Integer id) throws IOException {
        UserWithdrawalCash userWithdrawalCash = userWithdrawalCashService.getByPrimaryKey(id);
        userWithdrawalCash.setState(UserWithdrawalState.UNPASS);
        userWithdrawalCashService.update(userWithdrawalCash);
        response.sendRedirect("withdrawCashPage");
    }

    @RequestMapping("/statistical/complete")
    public void withdrawalComplete(HttpServletResponse response,
                                   Integer id) throws IOException {
        UserWithdrawalCash userWithdrawalCash = userWithdrawalCashService.getByPrimaryKey(id);
        userWithdrawalCash.setState(UserWithdrawalState.COMPLETED);
        userWithdrawalCash.setApplyFinishTime(LocalDateTime.now());
        userWithdrawalCashService.update(userWithdrawalCash);
        response.sendRedirect("withdrawCashPage");
    }

    /**
     * 资金流水 收款流水
     */
    @RequestMapping("/capital/cashier")
    public BaseDto capitalCashier(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                                  @RequestParam(defaultValue = "15", value = "pageSize") int pageSize) {
        BaseDto baseDto = new BaseDto();
        baseDto.setCode(CodeConst.OK);
        List<CashDealRecordDto> sysCashier = userCashHistoryService.getSysCashier(pageNum, pageSize);
        baseDto.setData(sysCashier);
        return baseDto;
//        List<UserDealHistory> feeHistory = userDealHistoryService.getAllFeeHistory();
//        ArrayList<CapitalList> capitalLists = new ArrayList<>();
//        //Page page = PageHelper.startPage(pageNum,pageSize);
//        if (feeHistory == null || feeHistory.isEmpty()) {
//        } else {
//            for (UserDealHistory userDealHistory : feeHistory) {
//                CapitalList capitalList = new CapitalList();
//                capitalList.setCount(userDealHistory.getDealAliveCoinCount());
//                capitalList.setPrice(userDealHistory.getDealAliveCoinCount().multiply(userDealHistory.getSinglePrice()));
//                capitalList.setCreateTime(userDealHistory.getCreateTime());
//                capitalList.setDealType("手续费");
//                capitalList.setSinglePrice(new BigDecimal(0));
//                capitalLists.add(capitalList);
//            }
//        }
//
//        List<RechargeHistory> rechargeHistories = rechargeHistoryService.getsByPaymentStatus(PaymentStatus.PAID);
//        if (rechargeHistories == null || rechargeHistories.isEmpty()) {
//        } else {
//            for (RechargeHistory rechargeHistory : rechargeHistories) {
//                CapitalList capitalList = new CapitalList();
//                capitalList.setPrice(new BigDecimal(rechargeHistory.getFee()));
//                capitalList.setCreateTime(rechargeHistory.getCreateTime());
//                capitalList.setSinglePrice(new BigDecimal(0));
//                capitalList.setCount(new BigDecimal(0));
//                capitalList.setDealType("用户充值");
//                capitalLists.add(capitalList);
//            }
//        }
//
//        List<ShareholderBuyGrantHistory> buyGrantHistoryList = shareholderBuyGrantHistoryService.getAll();
//        if (buyGrantHistoryList == null || buyGrantHistoryList.isEmpty()) {
//        } else {
//            for (ShareholderBuyGrantHistory buy : buyGrantHistoryList) {
//                CapitalList capitalList = new CapitalList();
//                capitalList.setCreateTime(buy.getCreateTime());
//                capitalList.setDealType("股东贡献本金");
//                capitalList.setSinglePrice(buy.getSinglePrice());
//                capitalList.setCount(buy.getCount());
//                capitalList.setPrice(buy.getSinglePrice().multiply(buy.getCount()));
//                capitalLists.add(capitalList);
//            }
//        }
//
//        // TODO: 2019-04-20 二期数据:超管发布挂买单(会员买入)
//        PageInfo<CapitalList> pageInfo = new PageInfo<>(capitalLists);
//        //pageInfo.setTotal(page.getTotal());
//        baseDto.setData(pageInfo);
//        return baseDto;

    }

    /**
     * 资金流水 付款流水
     */
    @RequestMapping("/capital/pay")
    public BaseDto capitalPay(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum,
                              @RequestParam(defaultValue = "15", value = "pageSize") int pageSize) {
        BaseDto baseDto = new BaseDto();
        baseDto.setCode(CodeConst.OK);
        List<CashDealRecordDto> sysCashier = userCashHistoryService.getSysPay(pageNum, pageSize);
        baseDto.setData(sysCashier);
        return baseDto;
//        List<UserWithdrawalCash> userWithdrawalCashList = userWithdrawalCashService.getsCompleted(UserWithdrawalState.COMPLETED);
//        ArrayList<CapitalList> capitalLists = new ArrayList<>();
//        BigDecimal price = new BigDecimal(0);
//        BigDecimal count = new BigDecimal(0);
//        BigDecimal singlePrice = new BigDecimal(0);
//
//        //Page page = PageHelper.startPage(pageNum,pageSize);
//        if (userWithdrawalCashList == null || userWithdrawalCashList.isEmpty()) {
//        } else {
//            for (UserWithdrawalCash userWithdrawalCash : userWithdrawalCashList) {
//                CapitalList capitalList = new CapitalList();
//                price = price.add(new BigDecimal(userWithdrawalCash.getApplyMoney()));
//                capitalList.setCount(count);
//                capitalList.setPrice(price);
//                capitalList.setCreateTime(userWithdrawalCash.getApplyFinishTime());
//                capitalList.setDealType("提现");
//                capitalList.setSinglePrice(singlePrice);
//                capitalLists.add(capitalList);
//            }
//        }
//
//        List<UserDealHistory> userDealHistories = userDealHistoryService.getsByDealScene(4);
//        if (userDealHistories == null || userDealHistories.isEmpty()) {
//        } else {
//            for (UserDealHistory userDealHistory : userDealHistories) {
//                CapitalList capitalList = new CapitalList();
//                BigDecimal totalPrice = new BigDecimal(0);
//                capitalList.setCreateTime(userDealHistory.getCreateTime());
//                capitalList.setDealType("系统回购");
//                BigDecimal dealAliveCoinCount = userDealHistory.getDealAliveCoinCount();
//                singlePrice = userDealHistory.getSinglePrice();
//                BigDecimal multiply = dealAliveCoinCount.multiply(singlePrice);
//                totalPrice = totalPrice.add(multiply);
//                capitalList.setSinglePrice(singlePrice);
//                capitalList.setCount(dealAliveCoinCount);
//                capitalList.setPrice(totalPrice);
//                capitalLists.add(capitalList);
//            }
//        }
//        List<ShareholderBonusList> bonusLists = shareholderBonusListService.getAll();
//        if (bonusLists == null || bonusLists.isEmpty()) {
//        } else {
//            for (ShareholderBonusList bonusList : bonusLists) {
//                CapitalList capitalList = new CapitalList();
//                BigDecimal successBonus = bonusList.getSuccessBonus();
//                LocalDate createDate = bonusList.getCreateDate();
//                Date date = Date.from(createDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
//                LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
//                capitalList.setCreateTime(localDateTime);
//                capitalList.setDealType("分红");
//                capitalList.setCount(new BigDecimal(0));
//                capitalList.setSinglePrice(new BigDecimal(0));
//                capitalList.setPrice(successBonus);
//                capitalLists.add(capitalList);
//            }
//        }
//        BaseDto baseDto = new BaseDto();
//        PageInfo<CapitalList> pageInfo = new PageInfo<>(capitalLists);
//        //pageInfo.setTotal(page.getTotal());
//        baseDto.setData(pageInfo);
//        return baseDto;
    }

    @RequestMapping("/deal/openPriceHistory")
    public List<OpenPriceHistory> getsOpenPriceHistoryByCoinTypeId(@RequestParam(defaultValue = "1", value = "coinTypeId") int coinTypeId) {
        return openPriceHistoryService.getsByCoinTypeId(coinTypeId);

    }

}